﻿namespace Fantom.Models
{
	internal class Slide : EchoBaseObject, ISlide
	{
		#region events
		public event SelectableEventHandler OnSelect;
		public event SelectableEventHandler LostSelect;
		#endregion

		#region properties

		public IShapes Shapes { get; private set; } = new Shapes();

		public int Index => (Parent as Slides).IndexOf(this);

		public Tags Tags { get; private set; } = new Tags();

		public IApplication Application { get; set; }

		public IFantomObject Parent { get; set; }

		private bool _isSelected = false;

		public bool IsSelected
		{
			get => _isSelected;

			set
			{
				var oldstate = _isSelected;
				_isSelected = value;

				if (value != oldstate)
				{
					if (value)
						OnSelect?.Invoke(this.Parent as ISlides, new[] { this });
					else
						LostSelect?.Invoke(this.Parent as ISlides, new[] { this });
				}

				PropertyChangedInvoke();
			}
		}

		public ICustomXmlList CustomXmlList { get; private set; } = new CustomXmlList();

		public ITimeLine TimeLine { get; set; } = null;

		#endregion

		#region methods
		public override string ToString()
		{
			return string.Format("SlideId: {0}", Index);
		}

		public void Select()
		{
			IsSelected = true;
		}

		public void UnSelect()
		{
			IsSelected = false;
		}
		#endregion

	}
}
